package com.ln.dm1103.demo01;

import java.util.*;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/3 15:58
 */
public class Test03 {
    public static void main(String[] args) {
        List<Teacher> list = new ArrayList<>();
        list.add(new Teacher("张三",18));
        list.add(new Teacher("李四",17));
        list.add(new Teacher("王五",16));
        list.add(new Teacher("二愣子",17));

        Comparator<Teacher> comparator=(o1,o2)->{
            return o1.getAge()-o2.getAge();
        };
        Collections.sort(list,comparator);

        System.out.println(list);
    }
}
class Teacher{
    private String name;
    private int age;

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
